<?php
namespace app\index\controller;

use app\common\controller\Base;
use app\index\model\Op;

class Opera extends Base
{

    /**
     * 控制器初始化
     * @return   void
     */
    public function _initialize()
    {
        //基类授权
        //
        parent::_initialize();
    }

    /**
     * 操作日志
     * @DateTime 2017-12-13
     * @return   void
     */
    public function log()
    {
        try {

            if (input('?get.method')) {
                switch ($method) {
                    case 'Game.login': //登录处理

                        $data = [
                            'cid'         => input('get.uid/d'),
                            'method'      => input('get.method/s'),
                            'create_time' => time(),
                        ];
                        if (input('?get.msg')) {
                            $data['msg'] = input('get.msg/s');
                        }
                        break;

                    default:
                        $data = [
                            'cid'         => input('get.cid/d'),
                            'method'      => input('get.method/s'),
                            'msg'         => input('get.msg/s'),
                            'create_time' => time(),
                        ];
                }

                //模型保存数据
                $affected = Op::insert($data);

                //判断是否新增成功,成功则提示信息
                $msg  = $affected ? "ok" : 'no work';
                $code = $affected ? 0 : 1;
                echo json_encode(['msg' => $msg, 'code' => $code]);
            } else {
                echo json_encode(['msg' => 'error : param method not exist', 'code' => 2]);
            }

        } catch (\Exception $e) {
            throw new \think\Exception('异常消息:' . $e->getMessage());
        }
    }
}
